package com.collect.senegal.zhiScene.zhiDsChangeWallet.zhiFollow;

import android.content.Context;

import com.collect.senegal.zhiBase.BasePresenter;
import com.collect.senegal.zhiBase.BaseSubscriber;
import com.collect.senegal.zhiBean.zhiReceive.ZHIRDsChangeWalletEntity;
import com.collect.senegal.zhiBean.zhiReceive.ZHIRDsChangeWalletSmsContentEntity;
import com.collect.senegal.zhiBean.zhiSend.ZHISDSChangeWalletSmsEntity;
import com.collect.senegal.zhiBean.zhiSend.ZHISDSGetChangeWalletInfoEntity;
import com.collect.senegal.zhiNetApi.ZHIHttpApiProvider;
import com.collect.senegal.zhiNetApi.ZHIHttpResponse;
import com.collect.senegal.zhiUtils.RxSchedulers;

import javax.inject.Inject;

public class ZHIDsChangeWalletFollowPresenter extends BasePresenter<ZHIDsChangeWalletFollowContract.View> implements ZHIDsChangeWalletFollowContract.Presenter {

    @Inject
    public ZHIDsChangeWalletFollowPresenter() {

    }

    @Override
    public void fetchChangeWalletUserInfo(Context context, ZHISDSGetChangeWalletInfoEntity zhisdsGetChangeWalletInfoEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ZHIRDsChangeWalletEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRDsChangeWalletEntity>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRDsChangeWalletEntity zhirDsChangeWalletEntity = (ZHIRDsChangeWalletEntity) object;
                            mView.onFetchChangeWalletUserInfo(zhirDsChangeWalletEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().fetchChangeWalletUserInfo(zhisdsGetChangeWalletInfoEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void sendChangeWalletUserSms(Context context, ZHISDSChangeWalletSmsEntity zhisdsChangeWalletSmsEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ZHIRDsChangeWalletSmsContentEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRDsChangeWalletSmsContentEntity>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRDsChangeWalletSmsContentEntity zhirDsChangeWalletSmsContentEntity = (ZHIRDsChangeWalletSmsContentEntity) object;
                            mView.onSendChangeWalletUserSms(zhirDsChangeWalletSmsContentEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().sendChangeWalletUserSms(zhisdsChangeWalletSmsEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }



    @Override
    public void cancelApplyOrder(Context context, ZHISDSChangeWalletSmsEntity zhisdsChangeWalletSmsEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse> subscriber = new
                BaseSubscriber<ZHIHttpResponse>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            mView.onCancelApplyOrder();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().cancelApplyOrder(zhisdsChangeWalletSmsEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}
